package com.example.demo.controller;

import com.example.demo.model.Borrowing;
import com.example.demo.service.BorrowingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/borrowings")
public class BorrowingController {

    @Autowired
    private BorrowingService borrowingService;

    @Autowired
    private com.example.demo.service.UserService userService;



    @PostMapping("/return/{borrowingId}")
    @PreAuthorize("hasAnyRole('USER', 'ADMIN')")
    public String returnBook(@PathVariable Integer borrowingId) {
        borrowingService.returnBook(borrowingId);
        return "redirect:/borrowings/my";
    }




}